feature/likes (#41) #82
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | |
# 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: | |
# 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/ | |
# building the docker image | |
- name: Build the Docker image | |
run: | | |
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 |