Skip to content

Commit

Permalink
actions: Use docker actions
Browse files Browse the repository at this point in the history
  • Loading branch information
lens0021 committed Apr 16, 2021
1 parent 9103fae commit d9697e7
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,29 @@ env:
jobs:
docker_image_job:
runs-on: ubuntu-18.04
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v2
# don't need to use the actions/checkout when working with setup-buildx-action

- name: Build image
run: docker build . --tag $IMAGE_NAME
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Log into GitHub Container Registry
run: echo "${{ secrets.CR_PAT }}" | docker login https://ghcr.io -u femiwiki-bot --password-stdin
- name: Login to GitHub Container Registry
if: github.repository_owner == 'femiwiki'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: femiwiki-bot
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push image to GitHub Container Registry
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
VERSION=$(date +%Y-%m-%dT%H-%M)-$(echo ${{ github.sha }} | cut -c1-8)
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:latest
docker push $IMAGE_ID:$VERSION
docker push $IMAGE_ID:latest
- id: version
run: echo "::set-output name=version::$(date +%Y-%m-%dT%H-%M)-$(echo ${{ github.sha }} | cut -c1-8)"

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
cache-from: ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest
with:
push: ${{ github.repository_owner == 'femiwiki' }}
tags: |
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.version.outputs.version }}
ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest

0 comments on commit d9697e7

Please sign in to comment.