Skip to content

Instantly share code, notes, and snippets.

@tfkhdyt
Created August 23, 2024 13:47
Show Gist options
  • Save tfkhdyt/53885472785c4cb88a5438251305c3dd to your computer and use it in GitHub Desktop.
Save tfkhdyt/53885472785c4cb88a5438251305c3dd to your computer and use it in GitHub Desktop.
How to build docker image in github actions
name: Build and Deploy
on:
push:
branches:
- master
jobs:
migrate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Migrate the database
run: |
curl -fsSL -o ./dbmate https://github.com/amacneil/dbmate/releases/download/v2.19.0/dbmate-linux-amd64
chmod +x ./dbmate
realpath ./dbmate
./dbmate --wait -u ${{ secrets.DATABASE_URL }} -d ./infra/database/migrations -s ./infra/database/schema.sql up
build_and_deploy:
runs-on: ubuntu-latest
needs: migrate
steps:
- uses: actions/checkout@v4
- name: Build and push the image
run: |
docker login --username tfkhdyt --password ${{ secrets.GH_PAT }} ghcr.io
docker build -t ghcr.io/netovas-projects/crm-netovas-backoff:latest .
docker push ghcr.io/netovas-projects/crm-netovas-backoff:latest
clean:
runs-on: ubuntu-latest
name: Delete old images
needs: build_and_deploy
steps:
- uses: snok/[email protected]
with:
account: netovas-projects
token: ${{ secrets.GH_PAT }}
image-names: "crm-netovas-backoff"
cut-off: 2w
keep-n-most-recent: 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment