Skip to content

Commit

Permalink
Update main.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
mobergmann authored Oct 31, 2023
1 parent 65429f0 commit 97aeb5d
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,56 +9,66 @@ on:
env:
CARGO_TERM_COLOR: always
IMAGE_NAME: ghcr.io/${{ github.repository }}:latest
IMAGE_PATH: ./image.tar
IMAGE_PATH: image.tar

jobs:
# compilation job
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# build the project
- name: Build the project
run: cargo build --release --verbose
# upload neccesary build files as an artifact
- name: Archive build artifacts
uses: actions/upload-artifact@v3
with:
name: build-artifact
path: |
target/release/sport-challenge
# building the image job
container_build:
if: github.ref == 'refs/heads/main'
# only run on main branch and not other branches/ pull-requests
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v3
# download the previously created build artifact
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: build-artifact
path: target/release/sport-challenge
path: target/release/
# building the docker image
- name: Build the Docker image
run: |
chmod u+x target/release/sport-challenge
docker build . --file Dockerfile --tag $IMAGE_NAME
docker save $IMAGE_NAME > image.tar
# upload the docker image as an artifact
- name: Archive container artifacts
uses: actions/upload-artifact@v3
with:
name: container-image-artifact
path: image.tar

# deploying the image job
container_deploy:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
needs: container_build
steps:
- uses: actions/checkout@v3
# download the previously created docker image
- name: Download container artifact
uses: actions/download-artifact@v3
with:
name: container-image-artifact
# publish the image to GitHub packages
- 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
docker push image.tar

0 comments on commit 97aeb5d

Please sign in to comment.