Cloud Run Functions setup #45
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker | |
on: | |
pull_request: | |
branches: [main] | |
workflow_dispatch: | |
jobs: | |
build-and-push: | |
name: Build and push Docker Image | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '22.12.0' | |
- name: Set Branch Name | |
id: set_branch | |
run: echo "branch=${{ github.event.pull_request.head.ref }}" >> $GITHUB_OUTPUT | |
- name: Set Commit SHA | |
id: set_sha | |
run: echo "commit_sha=$(git rev-parse --short=7 ${{ github.event.pull_request.head.sha }})" >> $GITHUB_OUTPUT | |
- name: Set Tags | |
id: set_tags | |
run: | | |
BRANCH_TAG="${{ steps.set_branch.outputs.branch }}" | |
COMMIT_TAG="${{ steps.set_sha.outputs.commit_sha }}" | |
TAGS="$BRANCH_TAG,$COMMIT_TAG" | |
echo "tags=$TAGS" >> $GITHUB_OUTPUT | |
- name: Debug Tags | |
run: | | |
echo "Branch Tag: ${{ steps.set_branch.outputs.branch }}" | |
echo "Commit Tag: ${{ steps.set_sha.outputs.commit_sha }}" | |
echo "All Tags: ${{ steps.set_tags.outputs.tags }}" | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build Docker Image | |
run: | | |
IFS=',' read -r -a TAG_ARRAY <<< "${{ steps.set_tags.outputs.tags }}" | |
TAG_ARGS="" | |
for tag in "${TAG_ARRAY[@]}"; do | |
TAG_ARGS="$TAG_ARGS -t ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:$tag" | |
done | |
docker build $TAG_ARGS . | |
echo "Build Docker Image with tags $TAG_ARGS" | |
- name: Push Docker Image | |
run: | | |
IFS=',' read -r -a TAG_ARRAY <<< "${{ steps.set_tags.outputs.tags }}" | |
for tag in "${TAG_ARRAY[@]}"; do | |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:$tag | |
echo "Push Docker Image with tag $tag" | |
done |