push to docker

This commit is contained in:
Dave Horton
2023-04-10 09:43:25 -04:00
parent 66974c467d
commit 7923ececaf
+24 -23
View File
@@ -2,16 +2,8 @@ name: Docker
on: on:
push: push:
# Publish `main` as Docker `latest` image.
branches:
- main
# Publish `v1.2.3` tags as releases.
tags: tags:
- v* - '*'
env:
IMAGE_NAME: sbc-outbound
jobs: jobs:
push: push:
@@ -20,20 +12,13 @@ jobs:
if: github.event_name == 'push' if: github.event_name == 'push'
steps: steps:
- uses: actions/checkout@v3 - name: Checkout code
uses: actions/checkout@v3
- name: Build image - name: prepare tag
run: docker build . --file Dockerfile --tag $IMAGE_NAME id: prepare_tag
- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push image
run: | run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME IMAGE_ID=$GITHUB_REPOSITORY
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version # Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
@@ -47,5 +32,21 @@ jobs:
echo IMAGE_ID=$IMAGE_ID echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION echo "image_id=$IMAGE_ID" >> $GITHUB_OUTPUT
docker push $IMAGE_ID:$VERSION echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.prepare_tag.outputs.image_id }}:${{ steps.prepare_tag.outputs.version }}
build-args: |
GITHUB_REPOSITORY=$GITHUB_REPOSITORY
GITHUB_REF=$GITHUB_REF