Skip to content

Commit

Permalink
Changed docker cli commands to GH actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronaldo Macapobre committed Aug 29, 2024
1 parent 586e640 commit 1cdf282
Showing 1 changed file with 59 additions and 19 deletions.
78 changes: 59 additions & 19 deletions .github/workflows/publish-web.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@ on:
env:
WORKING_DIRECTORY: ./web
IMAGE_NAME: web
GITHUB_IMAGE_REPO: ghcr.io/bcgov/jasper/
GITHUB_IMAGE_REPO: ghcr.io/bcgov/jasper
WEB_BASE_HREF: /

jobs:
build:
name: Build, Create and Push Image
runs-on: ubuntu-latest
outputs:
image_digest: ${{ steps.docker_push.outputs.digest }}
short_sha: ${{ steps.short_sha.outputs.SHORT_SHA }}

strategy:
Expand Down Expand Up @@ -50,21 +49,65 @@ jobs:
run: |
echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- name: Build Docker Image
working-directory: ${{env.WORKING_DIRECTORY}}/../
run: |
docker build --tag web-runtime -f docker/nginx-runtime/Dockerfile ./docker/nginx-runtime/
docker build --tag web-artifacts --build-arg node_version=${{ matrix.node-major-version }} --build-arg WEB_BASE_HREF=${{ env.WEB_BASE_HREF }} -f docker/web/Dockerfile .
docker build --tag ${{ env.IMAGE_NAME }} -f docker/vue-on-nginx/Dockerfile ./docker/vue-on-nginx/
docker tag ${{ env.IMAGE_NAME }} ${{ env.GITHUB_IMAGE_REPO }}${{ env.IMAGE_NAME }}:${{ steps.short_sha.outputs.SHORT_SHA }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Push Image to GCHR
id: docker_push
run: |
output=$(docker push ${{ env.GITHUB_IMAGE_REPO }}${{ env.IMAGE_NAME }}:${{ steps.short_sha.outputs.SHORT_SHA }})
echo $output
digest=$(echo "$output" | grep "digest: sha256" | awk '{ print $3 }')
echo "digest=$digest" >> $GITHUB_OUTPUT
- name: Setup Image Metadata (web-runtime)
id: meta_wr
uses: docker/metadata-action@v5
with:
tags: |
type=raw,value=web-runtime
- name: Build web-runtime image
uses: docker/build-push-action@v5
with:
push: false
context: .
file: ./docker/nginx-runtime/Dockerfile
tags: ${{ steps.meta_wr.outputs.tags }}
labels: ${{ steps.meta_wr.outputs.labels }}
outputs: |
type=local,dest=./docker/nginx-runtime/
- name: Setup Image Metadata (web-artifacts)
id: meta_wa
uses: docker/metadata-action@v5
with:
tags: |
type=raw,value=web-artifacts
- name: Build web-artifacts image
uses: docker/build-push-action@v5
with:
push: false
context: .
file: ./docker/web/Dockerfile
tags: ${{ steps.meta_wa.outputs.tags }}
labels: ${{ steps.meta_wa.outputs.labels }}
build-args: |
node_version=${{ matrix.node-major-version }}
WEB_BASE_HREF=${{ env.WEB_BASE_HREF }}
- name: Setup Image Metadata ${{ env.IMAGE_NAME}}
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.GITHUB_IMAGE_REPO }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=${{ steps.short_sha.outputs.SHORT_SHA }}
- name: Build ${{ env.IMAGE_NAME}} image
uses: docker/build-push-action@v5
with:
push: true
context: .
file: ./docker/vue-on-nginx/Dockerfile
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
outputs: |
type=local,dest=./docker/vue-on-nginx/
deploy2dev:
name: Deploy to DEV
Expand Down Expand Up @@ -92,7 +135,6 @@ jobs:
ghcr_token: ${{ secrets.GITHUB_TOKEN }}
github_image_repo: ${{ env.GITHUB_IMAGE_REPO }}
image_name: ${{ env.IMAGE_NAME }}
image_digest: ${{ needs.build.outputs.image_digest }}
tier_name: web
short_sha: ${{ needs.build.outputs.short_sha }}

Expand Down Expand Up @@ -123,7 +165,6 @@ jobs:
# ghcr_token: ${{ secrets.GITHUB_TOKEN }}
# github_image_repo: ${{ env.GITHUB_IMAGE_REPO }}
# image_name: ${{ env.IMAGE_NAME }}
# image_digest: ${{ needs.build.outputs.image_digest }}
# tier_name: web
# short_sha: ${{ needs.build.outputs.short_sha }}

Expand Down Expand Up @@ -154,6 +195,5 @@ jobs:
# ghcr_token: ${{ secrets.GITHUB_TOKEN }}
# github_image_repo: ${{ env.GITHUB_IMAGE_REPO }}
# image_name: ${{ env.IMAGE_NAME }}
# image_digest: ${{ needs.build.outputs.image_digest }}
# tier_name: web
# short_sha: ${{ needs.build.outputs.short_sha }}

0 comments on commit 1cdf282

Please sign in to comment.