Skip to content

reduce workflow time by only including necessary files in artifact #3

reduce workflow time by only including necessary files in artifact

reduce workflow time by only including necessary files in artifact #3

Workflow file for this run

name: Build and Deploy
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
env:
CARGO_TERM_COLOR: always
IMAGE_NAME: ghcr.io/${{ github.repository }}:latest
IMAGE_PATH: ./image.tar
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build the project
run: cargo build --release --verbose
- name: Archive build artifacts
uses: actions/upload-artifact@v3
with:
name: build-artifact
path: |
target/release/sport-challenge
container_build:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: build-artifact
path: target/release/sport-challenge
- name: Build the Docker image
run: |
docker build . --file Dockerfile --tag $IMAGE_NAME
docker save $IMAGE_NAME > image.tar
- name: Archive container artifacts
uses: actions/upload-artifact@v3
with:
name: container-image-artifact
path: image.tar
container_deploy:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: container_build
steps:
- uses: actions/checkout@v3
- name: Download container artifact
uses: actions/download-artifact@v3
with:
name: container-image-artifact
- name: Publish the image
run: |
docker load < image.tar
docker login --username ${{ github.repository_owner }} --password ${{ secrets.GH_PAT }} ghcr.io
docker push $IMAGE_NAME