Last active
August 15, 2024 18:44
-
-
Save ijpatricio/fe3ea4029743a209a70358181144a267 to your computer and use it in GitHub Desktop.
Build ARM Images in GitHub Actions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Docker Image | |
on: | |
workflow_dispatch: | |
push: { branches: [ 'implement-docker' ] } | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_USER: your_username | |
IMAGE_NAME: your_username/project_name | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Login to GHCR | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ env.IMAGE_USER }} | |
password: ${{ secrets.GH_TOKEN }} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Get Composer Cache Directory | |
id: composer-cache | |
run: | | |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | |
- name: Cache Docker layers | |
uses: actions/cache@v3 | |
with: | |
path: | | |
/tmp/.buildx-cache | |
${{ steps.composer-cache.outputs.dir }} | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Extract metadata | |
id: meta | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
flavor: | | |
latest=true | |
tags: | | |
type=schedule,pattern={{date 'YYYYMMDD-HHmmss' tz='UTC'}} | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{major}}.{{minor}}.{{patch}} | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}} | |
type=sha | |
- name: Build and push | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
platforms: linux/amd64,linux/arm64 | |
file: ./docker/prod/Dockerfile | |
cache-from: | | |
type=local,src=/tmp/.buildx-cache | |
type=local,src=${{ steps.composer-cache.outputs.dir }} | |
cache-to: | | |
type=local,dest=/tmp/.buildx-cache | |
type=local,dest=${{ steps.composer-cache.outputs.dir }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# more stages... | |
# When using a Node image, make sure to use the amd64 version, or it will take forever | |
# GH Actions is running arm64 in a emulator (QEMU). This way, it will use the native amd64 and be much faster. | |
FROM --platform=linux/amd64 node:19 as static-assets | |
WORKDIR /app | |
COPY . . | |
RUN npm install ; npm run build | |
# more stages... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Prune Registry | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: 0 0 * * * | |
env: | |
# For image ghcr.io/foo/bar, it will use 'foo' because of the token, and 'bar' is the project_name | |
# For more options for configs, see https://github.com/vlaurin/action-ghcr-prune | |
PROJECT_NAME: project_name | |
jobs: | |
prune-images: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Prune | |
uses: vlaurin/action-ghcr-prune@v0.5.0 | |
with: | |
token: ${{ secrets.GH_TOKEN }} | |
container: ${{ env.PROJECT_NAME }} | |
dry-run: true # Dry-run first, then change to `false` | |
keep-younger-than: 0 # days | |
keep-last: 6 | |
prune-untagged: true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment