[CI] Move to appcd-dev action #222
Workflow file for this run
This file contains hidden or 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: Docker Publish | |
on: | |
push: | |
# Publish `main` as Docker `latest` image. | |
branches: | |
- main | |
# Publish `v1.2.3` tags as releases. | |
tags: | |
- v* | |
# Run tests for any PRs. | |
pull_request: | |
env: | |
# TODO: Change variable to your image's name. | |
IMAGE_NAME: dogeapi | |
jobs: | |
# Run tests. | |
# See also https://docs.docker.com/docker-hub/builds/automated-testing/ | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 1 | |
- name: Run tests | |
run: | | |
if [ -f docker-compose.test.yml ]; then | |
docker-compose --file docker-compose.test.yml build | |
docker-compose --file docker-compose.test.yml run sut | |
else | |
docker build . --file Dockerfile | |
fi | |
# Push image to GitHub Packages. | |
# See also https://docs.docker.com/docker-hub/builds/ | |
push: | |
# Ensure test job passes before pushing image. | |
needs: test | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' | |
permissions: | |
contents: write | |
packages: write | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 1 | |
- name: Build image | |
run: docker build . --file Dockerfile --tag $IMAGE_NAME | |
- name: Log into registry | |
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
- name: version output | |
id: version | |
run: | | |
# Strip git ref prefix from version | |
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | |
# Strip "v" prefix from tag name | |
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') | |
# Use Docker `latest` tag convention | |
[ "$VERSION" == "main" ] && VERSION=latest | |
echo "image_tag=$VERSION" >> $GITHUB_OUTPUT | |
- name: Push image | |
run: | | |
IMAGE_ID=ghcr.io/${{ github.repository }}/$IMAGE_NAME | |
# Change all uppercase to lowercase | |
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | |
echo IMAGE_ID=$IMAGE_ID | |
echo IMAGE_TAG=${{ steps.version.outputs.image_tag }} | |
docker tag $IMAGE_NAME $IMAGE_ID:${{ steps.version.outputs.image_tag }} | |
docker push $IMAGE_ID:${{ steps.version.outputs.image_tag }} | |
## generating helm charts as this artifact is not checked-in | |
- name: Create required directories | |
run: mkdir -p .appcd/charts && chmod 777 .appcd -R | |
- name: Generate IAC for main branch | |
env: | |
APPCD_TOKEN: ${{ secrets.APPCD_TOKEN }} | |
APPCD_URL: ${{ secrets.APPCD_URL }} | |
uses: appcd-dev/action@v0.0.1 | |
with: | |
cloud: 'aws' | |
language: 'Python' | |
outputDir: './.appcd/charts' | |
scanPath: './main_branch' | |
targetCompute: 'k8s' | |
- name: Inflate helm chart in gitops/ | |
run: | | |
tree | |
if [[ "${{ github.ref }}" == "refs/tags/"* ]]; then | |
helm template demo-chart ./.appcd/charts/dogeapi -f ./.appcd/overrides/dogeapi/values.yaml --set image.tag=${{ steps.version.outputs.image_tag }} > ./gitops/prod/dogeapi.yaml | |
else | |
helm template demo-chart ./.appcd/charts/dogeapi -f ./.appcd/overrides/dogeapi/values.yaml > ./gitops/dev/dogeapi.yaml | |
fi | |
# in real apps the gitops config and spec would in be a separate repo | |
- name: Commit changes to gitops/ | |
uses: stefanzweifel/git-auto-commit-action@v5 | |
with: | |
file_pattern: ./gitops/ | |
commit_message: "chore: update gitops" | |
branch: main |