diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6cae305..b33367c 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,45 +1,40 @@ name: Build and deploy containers -# Pushes to main will build containers with staging env's and push them as staging images, whereas release goes to production. -on: + +on: release: types: [published] push: branches: - main + env: IMAGE_NAME: ${{ github.event_name == 'release' && 'timetrials' || 'timetrials-staging' }} -jobs: - push_package: - if: ${{ github.event_name == 'release' || (github.event_name == 'push' && !contains(github.event.head_commit.message, '#no-deploy')) }} + build_todo_frontend: runs-on: ubuntu-latest - permissions: - packages: write - contents: read steps: - uses: actions/checkout@v4 - - name: Build image - run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" + - name: Extract Docker image metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: "${{ vars.DOCKER_USERNAME }}/{{ env.IMAGE_NAME }}" + # images: "${{ vars.DOCKER_USERNAME }}/${IMAGE_NAME}" - - name: Log in to registry - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin - # - - name: Push image - run: | - IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} - # This changes all uppercase characters to lowercase. - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - # This strips the git ref prefix from the version. - VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') - - # This strips the "v" prefix from the tag name. - [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') - - VERSION=latest - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - docker tag $IMAGE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: "{{defaultContext}}:timetrials" + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + annotations: ${{ steps.meta.outputs.annotations }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e0a476b..eac08dd 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,8 +1,8 @@ name: Deploy to fly.io and create version on: - push: - branches: - - main + # push: + # branches: + # - main env: FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}