forked from imranismail/relayman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from kfit-dev/chore/listen-ipv4-only
bump base image and libs
- Loading branch information
Showing
2 changed files
with
86 additions
and
41 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,25 @@ | ||
name: Docker | ||
name: Build relayman | ||
|
||
on: | ||
push: | ||
# Publish `master` as Docker `latest` image. | ||
branches: | ||
- master | ||
|
||
# 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: relayman | ||
ECR_REGISTRY: 606804169143.dkr.ecr.ap-southeast-1.amazonaws.com | ||
ECR_BUILD_REPO: relayman | ||
|
||
jobs: | ||
# Run tests. | ||
# See also https://docs.docker.com/docker-hub/builds/automated-testing/ | ||
test: | ||
runs-on: ubuntu-latest | ||
runs-on: ubuntu-20.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Run tests | ||
run: | | ||
if [ -f docker-compose.test.yml ]; then | ||
|
@@ -34,37 +28,88 @@ jobs: | |
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' | ||
setup_env: | ||
if: ${{ github.event_name == 'push' }} | ||
needs: test | ||
environment: test | ||
runs-on: ubuntu-20.04 | ||
outputs: | ||
ecr_password: ${{ steps.ecr_password.outputs.ecr_password }} | ||
container_image_uri: ${{ steps.image_tag.outputs.container_image_uri }} | ||
image_tag: ${{ steps.image_tag.outputs.image_tag }} | ||
steps: | ||
- name: Set up AWS CLI | ||
uses: chrislennon/[email protected] | ||
- id: ecr_password | ||
name: Retrieve ECR password | ||
env: | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
AWS_DEFAULT_REGION: ap-southeast-1 | ||
run: echo "ecr_password=$(aws ecr get-login-password)" >> $GITHUB_OUTPUT | ||
- id: image_tag | ||
name: Setup image tags | ||
run: | | ||
IMAGE_TAG=latest | ||
echo "image_tag=$IMAGE_TAG" >> $GITHUB_OUTPUT | ||
echo "container_image_uri=$ECR_REGISTRY/$ECR_BUILD_REPO:$IMAGE_TAG" >> $GITHUB_OUTPUT | ||
docker_build: | ||
if: ${{ github.event_name == 'push' }} | ||
timeout-minutes: 40 | ||
needs: | ||
- setup_env | ||
environment: test | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Check Out Repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Build image | ||
run: docker build . --file Dockerfile --tag $IMAGE_NAME | ||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v2 | ||
with: | ||
buildkitd-flags: --debug | ||
install: true | ||
|
||
- name: Cache Docker layers | ||
uses: actions/cache@v3 | ||
with: | ||
path: /tmp/.buildx-cache-${{ matrix.gemfile }} | ||
key: ${{ runner.os }}-multi-buildx-${{ github.sha }}-${{ matrix.gemfile }} | ||
restore-keys: | | ||
${{ runner.os }}-multi-buildx | ||
- name: Log into GitHub Container Registry | ||
# TODO: Create a PAT with `read:packages` and `write:packages` scopes and save it as an Actions secret `CR_PAT` | ||
run: echo "${{ secrets.CR_PAT }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ap-southeast-1 | ||
|
||
- name: Login to ECR | ||
uses: docker/login-action@v2 | ||
with: | ||
registry: ${{ env.ECR_REGISTRY }} | ||
|
||
- name: Build image | ||
uses: docker/build-push-action@v3 | ||
env: | ||
CONTAINER_IMAGE_URI: ${{ needs.setup_env.outputs.container_image_uri }} | ||
with: | ||
context: . | ||
builder: ${{ steps.buildx.outputs.name }} | ||
file: Dockerfile | ||
push: true | ||
tags: ${{ env.CONTAINER_IMAGE_URI }} | ||
cache-from: type=local,src=/tmp/.buildx-cache-${{ matrix.gemfile }} | ||
# Note the mode=max here | ||
# More: https://github.com/moby/buildkit#--export-cache-options | ||
# And: https://github.com/docker/buildx#--cache-tonametypetypekeyvalue | ||
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new-${{ matrix.gemfile }} | ||
|
||
- name: Push image to GitHub Container Registry | ||
- name: Move cache | ||
run: | | ||
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME | ||
# Change all uppercase to lowercase | ||
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | ||
# 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" == "master" ] && VERSION=latest | ||
echo IMAGE_ID=$IMAGE_ID | ||
echo VERSION=$VERSION | ||
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION | ||
docker push $IMAGE_ID:$VERSION | ||
rm -rf /tmp/.buildx-cache-${{ matrix.gemfile }} | ||
mv /tmp/.buildx-cache-new-${{ matrix.gemfile }} /tmp/.buildx-cache-${{ matrix.gemfile }} |
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