From fc3b32177b7a0fea0489393b69c6cb35f2cb9051 Mon Sep 17 00:00:00 2001 From: Tobias Hoge Date: Thu, 19 Sep 2024 18:55:40 +0200 Subject: [PATCH] add github actions to build image --- .github/workflows/ci.yml | 49 ++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f10d370..66a8a7a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,20 +11,41 @@ jobs: - name: test-image run: bin/ci - push: - name: Push to production server + build: + name: Build image and push to Gihub Registry (production branch only) needs: test runs-on: ubuntu-latest + steps: - - - name: checkout-repo - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Push to dokku - uses: dokku/github-action@v1.4.0 - with: - git_remote_url: ${{ secrets.GIT_REMOTE_URL }} - ssh_private_key: ${{ secrets.DOKKU_SSH_KEY }} - if: github.ref == 'refs/heads/production' + # Step 1: Check out the repository + - name: Checkout code + uses: actions/checkout@v3 + + # Step 2: Set up Docker Buildx (for cross-platform builds, if needed) + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + # Step 3: Log in to GitHub Container Registry + - name: Log in to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Step 4: Build the Docker image + - name: Build Docker image + run: | + docker build -t ghcr.io/${{ github.repository }}:${{ github.sha }} . + + # Step 5: Push the Docker image to GitHub Container Registry + - name: Push Docker image to GitHub Container Registry + run: | + docker push ghcr.io/${{ github.repository }}:${{ github.sha }} + + # Optional Step 6: Add latest tag and push it as well + - name: Tag image as latest and push + run: | + docker tag ghcr.io/${{ github.repository }}:${{ github.sha }} ghcr.io/${{ github.repository }}:latest + docker push ghcr.io/${{ github.repository }}:latest + if: github.ref == 'refs/heads/production'