Skip to content

Docker -- GHCR

Docker -- GHCR #5

Workflow file for this run

name: Docker -- GHCR
on:
workflow_dispatch:
push:
branches:
- main
paths:
- 'docker/**/*'
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
images:
- landing
- gitpod-fcc
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ matrix.images }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ matrix.images }}-
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./docker/${{ matrix.images }}
push: true
tags: |
ghcr.io/freecodecamp/${{ matrix.images }}:${{ github.sha }}
ghcr.io/freecodecamp/${{ matrix.images }}:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache