Skip to content

Commit

Permalink
Create build-and-publish-container-image.yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbouwer authored Apr 5, 2021
1 parent 6e9ac0e commit 09c24b1
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/build-and-publish-container-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: "When a release tag is created, build and publish a new version of the container image"

on:

create

jobs:

build-and-push-container-image:

runs-on: ubuntu-latest

if: startsWith(github.ref, 'refs/tags/v')

env:
CONTAINER_REGISTRY: docker.io
CONTAINER_IMAGE: paulbouwer/hello-kubernetes

steps:

- name: Checkout code
uses: actions/checkout@v2

- name: Build image and version variables
run: |
echo "IMAGE=$CONTAINER_REGISTRY/$CONTAINER_IMAGE" >> $GITHUB_ENV
echo "IMAGE_VERSION=$(cat src/app/package.json | jq -r .version)" >> $GITHUB_ENV
- name: Build additional image tag variables
run: |
echo "IMAGE_MAJOR_VERSION=$(echo $IMAGE_VERSION | cut -d '.' -f1)" >> $GITHUB_ENV
echo "IMAGE_MINOR_VERSION=$(echo $IMAGE_VERSION | cut -d '.' -f2)" >> $GITHUB_ENV
- name: Build image
run: |
docker build --tag "$IMAGE:$IMAGE_VERSION" \
--build-arg IMAGE_VERSION="$IMAGE_VERSION" \
--build-arg IMAGE_CREATE_DATE="`date -u +"%Y-%m-%dT%H:%M:%SZ"`" \
--build-arg IMAGE_SOURCE_REVISION="`git rev-parse HEAD`" \
--file src/app/Dockerfile src/app
- name: Create additional image tags
run: |
docker tag $IMAGE:$IMAGE_VERSION $IMAGE:$IMAGE_MAJOR_VERSION
docker tag $IMAGE:$IMAGE_VERSION $IMAGE:$IMAGE_MAJOR_VERSION.$IMAGE_MINOR_VERSION
- name: Log into registry
run: echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin

- name: Push image and tags to registry
run: |
docker push $IMAGE:$IMAGE_VERSION
docker push $IMAGE:$IMAGE_MAJOR_VERSION
docker push $IMAGE:$IMAGE_MAJOR_VERSION.$IMAGE_MINOR_VERSION

0 comments on commit 09c24b1

Please sign in to comment.