Skip to content

Build and push Docker image #27

Build and push Docker image

Build and push Docker image #27

name: Build and push Docker image
on: workflow_dispatch
jobs:
build-push-docker-image:
name: Build and push Docker image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Generate version
run: |
echo "VERSION=$(date +'%Y.%m.%d')-$GITHUB_RUN_NUMBER" >> $GITHUB_ENV
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: sa-east-1
- name: Login to Amazon ECR
uses: aws-actions/amazon-ecr-login@v2
- name: Setup Cargo cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
backend/target/
/usr/local/cargo/registry
key: ${{ runner.os }}-cargo-${{ hashFiles('backend/Cargo.lock') }}
- name: Get npm cache directory
id: npm-cache-dir
shell: bash
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- name: Setup npm cache
uses: actions/cache@v3
env:
DIR: ${{ env.dir }}
with:
path: ${DIR}
key: ${{ runner.os }}-node-${{ hashFiles('frontend/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Setup Docker build cache
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-docker-buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and push
env:
VERSION: ${{ env.VERSION }}
REPO: 859499744640.dkr.ecr.sa-east-1.amazonaws.com
CACHE: /tmp/.buildx-cache
run: |
docker buildx build --cache-from type=local,src=${CACHE} --cache-to type=local,dest=${CACHE} --platform linux/amd64 -t ${REPO}/windmill:latest -t ${REPO}/windmill:${VERSION} --push .
- name: Create version tag on repository
env:
VERSION: ${{ env.VERSION }}
run: |
git tag $VERSION
git push --tags