diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2460436d..fec97d81 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,6 +7,9 @@ on: pull_request: types: [opened, synchronize, reopened] +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} jobs: build: @@ -18,12 +21,16 @@ jobs: uses: docker/setup-qemu-action@v1 - name: Setup Docker buildx uses: docker/setup-buildx-action@v1 - - - name: Get Docker image metadata + - name: Retrieve author data run: | - echo IMAGE_REPOSITORY=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV - echo DATE=$(date --rfc-3339=seconds) >> $GITHUB_ENV echo AUTHOR=$(curl -sSL ${{ github.event.repository.owner.url }} | jq -r '.name') >> $GITHUB_ENV + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + labels: | + org.opencontainers.image.authors=${{ env.AUTHOR }} - name: Build Docker image uses: docker/build-push-action@v2 with: @@ -33,11 +40,9 @@ jobs: load: true cache-from: type=gha cache-to: type=gha,mode=max - tags: wg-access-server:testing - labels: | - org.opencontainers.image.created=${{ env.DATE }} - org.opencontainers.image.authors=${{ env.AUTHOR }} - org.opencontainers.image.source=${{ github.event.repository.clone_url }} - org.opencontainers.image.revision=${{ github.sha }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + org.opencontainers.image.authors: ${{ env.AUTHOR }} + - name: Inspect Docker image - run: docker image inspect wg-access-server:testing + run: docker image inspect ${{ steps.meta.outputs.tags }} diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 30c0cb17..b3718094 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -6,6 +6,10 @@ on: tags: - 'v*.*.*' +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + jobs: push_to_registry: name: Push Docker image to GitHub Packages @@ -23,16 +27,21 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - name: Login to DockerHub - uses: docker/login-action@v1 + uses: docker/login-action@v1 with: - registry: ghcr.io + registry: ${{ env.REGISTRY }} username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Get Docker image metadata + - name: Retrieve author data run: | - echo IMAGE_REPOSITORY=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV - echo DATE=$(date --rfc-3339=seconds) >> $GITHUB_ENV echo AUTHOR=$(curl -sSL ${{ github.event.repository.owner.url }} | jq -r '.name') >> $GITHUB_ENV + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + labels: | + org.opencontainers.image.authors=${{ env.AUTHOR }} - name: Build container image uses: docker/build-push-action@v2 with: @@ -41,10 +50,5 @@ jobs: push: true cache-from: type=gha cache-to: type=gha,mode=max - tags: | - ghcr.io/${{ env.IMAGE_REPOSITORY }}:latest - labels: | - org.opencontainers.image.created=${{ env.DATE }} - org.opencontainers.image.authors=${{ env.AUTHOR }} - org.opencontainers.image.source=${{ github.event.repository.clone_url }} - org.opencontainers.image.revision=${{ github.sha }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }}